package com.hackerrank.challenges.stackexchangescraper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Solution {
	private static final String SUMMARY = "summary";
	private static class Tag {
		public static final String TAG_ANCHOR = "a", TAG_DIV = "div", TAG_H3 = "h3", TAG_ROOT = "root", TAG_SPAN = "span", TAG_TEXT = "text";
		public static final String ATTR_CLASS = "class", ATTR_ID = "id", ATTR_VALUE = "value";
		String name;
		Map<String, String> attr = new HashMap<String, String>();
		List<Tag> body = new ArrayList<Tag>();
		public Tag(String name) {
			this.name = name;
		}
		public List<Tag> findTags(String tagName, String attrName, String attrValue) {
			List<Tag> tags = new ArrayList<Tag>();
			for(Tag tag : body) {
				if(tag.name.equalsIgnoreCase(tagName)) {
					String eAttrValue = tag.attr.get(attrName);
					if(eAttrValue != null && eAttrValue.equalsIgnoreCase(attrValue)) {
						tags.add(tag);
						continue;
					}
				}
				tags.addAll(tag.findTags(tagName, attrName, attrValue));
			}
			return tags;
		}
		public Tag findTag(String tagName, String attrName, String attrValue) {
			for(Tag tag : body) {
				if(tag.name.equalsIgnoreCase(tagName)) {
					String eAttrValue = tag.attr.get(attrName);
					if(eAttrValue != null && eAttrValue.equalsIgnoreCase(attrValue))
						return tag;
				}
				Tag foundTag = tag.findTag(tagName, attrName, attrValue);
				if(foundTag != null)
					return foundTag;
			}
			return null;
		}
		public Tag getTag(String tagName) {
			for(Tag tag : body)
				if(tag.name.equalsIgnoreCase(tagName))
					return tag;
			return null;
		}
		public Tag getTag(String tagName, String attrName, String attrValue) {
			for(Tag tag : body) {
				if(tag.name.equalsIgnoreCase(tagName)) {
					String eAttrValue = tag.attr.get(attrName);
					if(eAttrValue != null && eAttrValue.equalsIgnoreCase(attrValue))
						return tag;
				}
			}
			return null;
		}
		public String toString() {
			StringBuilder b = new StringBuilder("<");
			b.append(name);
			for(String attrName : attr.keySet()) {
				String attrValue = attr.get(attrName);
				b.append(" ").append(attrName).append("=").append(attrValue);
			}
			b.append(">");
			for(Tag tag : body)
				b.append(tag.toString());
			b.append("</").append(name).append(">");
			return b.toString();
		}
	}
	private static class TagParser {
		int i;
		char c[];
		public List<Tag> parseBody(String s) {
			i = 0;
			c = s.toCharArray();
			return parseBody();
		}
		private List<Tag> parseBody() {
			List<Tag> l = new ArrayList<Tag>();
			try {
				while(i < c.length) {
					while(Character.isSpaceChar(c[i]))
						i++;
					StringBuilder value = new StringBuilder();
					// considering end of input as end of value
					while(i < c.length && c[i] != '<')
						value.append(c[i++]);
					if(value.length() > 0) {
						Tag text = new Tag(Tag.TAG_TEXT);
						text.attr.put(Tag.ATTR_VALUE, value.toString());
						l.add(text);
					}
					int j = i;
					while(Character.isSpaceChar(c[++j]));
					if(c[j] == '/')
						break;
					l.add(parseTag());
				}
			} catch(Exception e) {
				// expecting only ArrayIndexOutOfBoundsException, therefore ignoring
			}
			return l;
		}
		private Tag parseTag() {
			assert(c[i] == '<');
			while(Character.isSpaceChar(c[++i]));
			StringBuilder tagName = new StringBuilder();
			// considering end of input as end of tag name
			while(i < c.length && !Character.isSpaceChar(c[i]) && c[i] != '>')
				tagName.append(c[i++]);
			Tag tag = new Tag(tagName.toString());
			try {
				while(Character.isSpaceChar(c[i]))
					i++;
				// TODO: handle self closing tags like <br/> and tags that do not need close tags like <br> etc
				while(c[i] != '>') {
					StringBuilder attrName = new StringBuilder(), attrValue = new StringBuilder();
					// considering end of input as end of attribute name
					while(i < c.length && !Character.isSpaceChar(c[i]) && c[i] != '=' && c[i] != '>')
						attrName.append(c[i++]);
					try {
						while(Character.isSpaceChar(c[i]))
							i++;
						if(c[i] == '=') {
							while(Character.isSpaceChar(c[++i]));
							if(c[i] == '"') {
								while(c[++i] != '"') {
									if(c[i] == '\\')
										attrValue.append(c[++i]);
									else
										attrValue.append(c[i]);
								}
								i++;
							} else if(c[i] == '\'') {
								while(c[++i] != '\'') {
									if(c[i] == '\\')
										attrValue.append(c[++i]);
									else
										attrValue.append(c[i]);
								}
								i++;
							} else {
								while(!Character.isSpaceChar(c[i]) && c[i] != '>')
									attrValue.append(c[i++]);
							}
							while(Character.isSpaceChar(c[i]))
								i++;
						}
					} catch(Exception e) {
						// expecting only ArrayIndexOutOfBoundsException, therefore ignoring
					}
					tag.attr.put(attrName.toString(), attrValue.toString().trim());
				}
				i++;
				tag.body = parseBody();
				int j = i;
				assert(c[j] == '<');
				while(Character.isSpaceChar(c[++j]));
				assert(c[j] == '/');
				while(Character.isSpaceChar(c[++j]));
				StringBuilder endTagName = new StringBuilder();
				while(!Character.isSpaceChar(c[j]) && c[j] != '>')
					endTagName.append(c[j++]);
				if(!endTagName.toString().equals(tagName.toString()))
					return tag;
				while(Character.isSpaceChar(c[j]))
					j++;
				assert(c[j] == '>');
				i = j + 1;
			} catch(Exception e) {
				// expecting only ArrayIndexOutOfBoundsException, therefore ignoring
			}
			return tag;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder input = new StringBuilder();
		while(in.hasNext())
			input.append(in.nextLine());
		Tag root = new Tag(Tag.TAG_ROOT);
		root.body = new TagParser().parseBody(input.toString());
		List<Tag> questions = root.findTags(Tag.TAG_DIV, Tag.ATTR_CLASS, "question-summary");
		for(Tag question : questions) {
			String id = question.attr.get(Tag.ATTR_ID).split("-")[2];
			Tag summary = question.getTag(Tag.TAG_DIV, Tag.ATTR_CLASS, SUMMARY);
			String questionText = summary.getTag(Tag.TAG_H3).getTag(Tag.TAG_ANCHOR).getTag(Tag.TAG_TEXT).attr.get(Tag.ATTR_VALUE);
			String time = summary.findTag(Tag.TAG_SPAN, Tag.ATTR_CLASS, "relativetime").getTag(Tag.TAG_TEXT).attr.get(Tag.ATTR_VALUE);
			System.out.println(id + ";" + questionText + ";" + time);
		}
	}
}
